<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Java,">





  <link rel="alternate" href="/atom.xml" title="DG" type="application/atom+xml">






<meta name="description" content="Day39XML1234567可扩展的标记语言他里面所有的标签都是自定义.xml的梦想:	1.干掉html ---&amp;gt;失败告终, 语法严格,但是功能没有提高	2.干掉数据库 ---&amp;gt;失败告终, 没有数据库的效率高, 而且固定规范	3.作为网络的数据载体 ---&amp;gt;以失败告终,后期被json替代了,因为json表示同等数据,体积小,传输熟虑快	4.作为配置文件 ----&amp;gt;成功了,">
<meta name="keywords" content="Java">
<meta property="og:type" content="article">
<meta property="og:title" content="Day39_XML">
<meta property="og:url" content="http://zhaowenhao99.github.io/2019/10/29/Day39_XML/index.html">
<meta property="og:site_name" content="DG">
<meta property="og:description" content="Day39XML1234567可扩展的标记语言他里面所有的标签都是自定义.xml的梦想:	1.干掉html ---&amp;gt;失败告终, 语法严格,但是功能没有提高	2.干掉数据库 ---&amp;gt;失败告终, 没有数据库的效率高, 而且固定规范	3.作为网络的数据载体 ---&amp;gt;以失败告终,后期被json替代了,因为json表示同等数据,体积小,传输熟虑快	4.作为配置文件 ----&amp;gt;成功了,">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-10-29T12:37:27.056Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Day39_XML">
<meta name="twitter:description" content="Day39XML1234567可扩展的标记语言他里面所有的标签都是自定义.xml的梦想:	1.干掉html ---&amp;gt;失败告终, 语法严格,但是功能没有提高	2.干掉数据库 ---&amp;gt;失败告终, 没有数据库的效率高, 而且固定规范	3.作为网络的数据载体 ---&amp;gt;以失败告终,后期被json替代了,因为json表示同等数据,体积小,传输熟虑快	4.作为配置文件 ----&amp;gt;成功了,">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://zhaowenhao99.github.io/2019/10/29/Day39_XML/">





  <title>Day39_XML | DG</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    <a href="https://zhaowenhao99.github.io/" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#151513; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">DG</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://zhaowenhao99.github.io/2019/10/29/Day39_XML/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="大狗">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/icon.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="DG">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Day39_XML</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-10-29T08:29:48+08:00">
                2019-10-29
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/学习/" itemprop="url" rel="index">
                    <span itemprop="name">学习</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
               <span title="字数统计">
                    2.6k 字 
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                    9 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="Day39"><a href="#Day39" class="headerlink" title="Day39"></a>Day39</h1><h3 id="XML"><a href="#XML" class="headerlink" title="XML"></a>XML</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">可扩展的标记语言</span><br><span class="line">他里面所有的标签都是自定义.</span><br><span class="line">xml的梦想:</span><br><span class="line">	1.干掉html ---&gt;失败告终, 语法严格,但是功能没有提高</span><br><span class="line">	2.干掉数据库 ---&gt;失败告终, 没有数据库的效率高, 而且固定规范</span><br><span class="line">	3.作为网络的数据载体 ---&gt;以失败告终,后期被json替代了,因为json表示同等数据,体积小,传输熟虑快</span><br><span class="line">	4.作为配置文件 ----&gt;成功了, 比properties的结构更清晰,能够识别多个数据, 后期有一部分的功能被注解替代了!!!!</span><br></pre></td></tr></table></figure>
<h3 id="xml的语法"><a href="#xml的语法" class="headerlink" title="xml的语法"></a>xml的语法</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">1.后缀名为.xml</span><br><span class="line">2.文档声明必须顶着第一行</span><br><span class="line">3.跟标签有且只能一个</span><br><span class="line">4.标签要正确闭合</span><br><span class="line">5.属性必须用引号引起来</span><br><span class="line">6.区分大小写</span><br></pre></td></tr></table></figure>
<h3 id="xml的组成"><a href="#xml的组成" class="headerlink" title="xml的组成"></a>xml的组成</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">1.文档声明</span><br><span class="line">	version =&apos;1.0&apos;</span><br><span class="line">	encoding=&quot;utf-8&quot;</span><br><span class="line">2.指令(css)凉凉</span><br><span class="line">3.元素</span><br><span class="line">	不能数字开头, 不能以xml或者XML开头</span><br><span class="line">	不能有特殊字符</span><br><span class="line">	</span><br><span class="line">4.属性:</span><br><span class="line">	约束中对属性有ID约束, 要求属性不能重复!!!!!!</span><br><span class="line">	id属性约束</span><br><span class="line">5.文本:</span><br><span class="line">	如何原样展示数据</span><br><span class="line">	&lt;![CDATA[ 数据 ]]&gt;</span><br></pre></td></tr></table></figure>
<h3 id="约束"><a href="#约束" class="headerlink" title="约束"></a>约束</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line">作用: 用来规定xml的书写规则</span><br><span class="line">dtd:</span><br><span class="line">	缺点:</span><br><span class="line">		1.不能对文本进行细节的操作, 比如,数字的范围, 性别只能在male和female, </span><br><span class="line">		2.一个xml中只能引入一个dtd</span><br><span class="line">	ELEMENT:用来规定标签的</span><br><span class="line">		格式:</span><br><span class="line">			&lt;!ELEMENT 标签名 (标签内容)&gt;</span><br><span class="line">				标签内容:</span><br><span class="line">					可以是子标签</span><br><span class="line">					可以是#PCDATA普通文本</span><br><span class="line">				量词:</span><br><span class="line">					+:一次或多次</span><br><span class="line">					?:0次或一次</span><br><span class="line">					*:0次或多次</span><br><span class="line">					没有量词: 表示出现有且只能一次</span><br><span class="line">		例如:</span><br><span class="line">			&lt;!ELEMENT students (student+)&gt;</span><br><span class="line">			代表: 规定students标签, 下面只能有student标签, student可以出现一次或多次</span><br><span class="line">	ATTLIST:用来规定属性的</span><br><span class="line">		格式:</span><br><span class="line">			&lt;!ATTLIST 标签名 属性名  属性的类型 属性出现的要求&gt;</span><br><span class="line">		例如:</span><br><span class="line">			&lt;!ATTLIST student name  CDATA #REQUERED&gt;</span><br><span class="line">			代表student标签上必须出现name属性, name属性的值是纯文本</span><br><span class="line">schema:</span><br><span class="line">	优点: 1.可以对文本进行跟细节的操作, 2. 一个xml可以引入多个schema,多个schema用名称空间(命名空间)区分</span><br><span class="line">	</span><br><span class="line">	元约束: 用来约束约束文档的约束, 是w3c提供一些基本的约束</span><br><span class="line">	约束文档: 用来约束实例文档的约束</span><br><span class="line">		编写约束文档步骤:</span><br><span class="line">			1.引入元约束 ---&gt;其实就是告诉这是一个约束文档	</span><br><span class="line">				 xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;</span><br><span class="line">			2.起名称空间(要符合url基本编写规则,比如: http://www.baidu.com)</span><br><span class="line">				作用: 用来区分多个约束文档中相同的标签用的</span><br><span class="line">				xmlns=&quot;http://www.itcast.cn/xml&quot;</span><br><span class="line">			3.编写约束条件</span><br><span class="line">				</span><br><span class="line">	实例文档:</span><br><span class="line">		编写实例文档的步骤:</span><br><span class="line">			1.告诉w3c我是一个实例文档:</span><br><span class="line">				 xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><br><span class="line">				 因为其xsd本质也是xml, 需要通过这个来告知是一个实例文档</span><br><span class="line">			2.引入约束文档</span><br><span class="line">				 xsi:schemaLocation=&quot;约束的名称空间  约束的位置&quot;</span><br><span class="line">				 例如:</span><br><span class="line">				  xsi:schemaLocation=&quot;http://www.itcast.cn/xml  stu.xml&quot;</span><br><span class="line">			3.为约束文档起别名</span><br><span class="line">				xmlns:别名=&quot;约束的名称空间&quot;</span><br><span class="line">				例如:</span><br><span class="line">				xmlns:aa=&quot;http://www.itcast.cn/xml&quot;</span><br></pre></td></tr></table></figure>
<h3 id="解析思想"><a href="#解析思想" class="headerlink" title="解析思想"></a>解析思想</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">	</span><br><span class="line">DOM:</span><br><span class="line">	1.将xml一次性加载进内存, 形成dom树</span><br><span class="line">	缺点:占内存</span><br><span class="line">	优点:能够进行crud所有操作,符合操作习惯</span><br><span class="line">SAX:</span><br><span class="line">	1.逐行解析, 基于事件驱动</span><br><span class="line">	缺点: 性能比较低,只能读取操作</span><br><span class="line">	优点: 不会出现内存溢出, 因为第一行释放一行</span><br></pre></td></tr></table></figure>
<h3 id="解析器"><a href="#解析器" class="headerlink" title="解析器"></a>解析器</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">JAXP:sun公司提供的谁都不用的, dom,sax</span><br><span class="line">dom4j:dom思想, 支持crud的操作</span><br><span class="line">jsoup:dom思想</span><br><span class="line"></span><br><span class="line">pull:sax思想, 一般用于手机端</span><br></pre></td></tr></table></figure>
<h3 id="常见的对象"><a href="#常见的对象" class="headerlink" title="常见的对象"></a>常见的对象</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line">Jsoup</span><br><span class="line">	parse(new File(xml的路径),&quot;xml的编码&quot;)(!!!!!!!!!!!!!!!!!!!)</span><br><span class="line">	parse(URL 网址,超时的时间)</span><br><span class="line">Document</span><br><span class="line">	作用:获取元素对象</span><br><span class="line">	getElementById(); ----&gt;根据id值获取元素对象, 只能获取一个</span><br><span class="line">	Elements getElementsByTag(&quot;标签名&quot;) ----&gt;根据标签名获取元素, 返回的元素的集合 </span><br><span class="line">	Elements getElementsByAttribute(&quot;属性名&quot;) ----&gt;根据属性名名获取元素, 返回的元素的集合 </span><br><span class="line">	Elements getElementsByAttributeValue(&quot;属性名&quot;,&quot;属性值&quot;) ----&gt;根据属性名=属性值,名获取元素, 返回的元素的集合 </span><br><span class="line">Element</span><br><span class="line">	获取元素方法:(注意这个只能站在某个元素下去找这个元素下面的子标签)</span><br><span class="line">		getElementById(); ----&gt;根据id值获取元素对象, 只能获取一个</span><br><span class="line">		Elements getElementsByTag(&quot;标签名&quot;) ----&gt;根据标签名获取元素, 返回的元素的集合 </span><br><span class="line">		Elements getElementsByAttribute(&quot;属性名&quot;) ----&gt;根据属性名名获取元素, 返回的元素的集合 </span><br><span class="line">		Elements getElementsByAttributeValue(&quot;属性名&quot;,&quot;属性值&quot;) ----&gt;根据属性名=属性值,名获取元素, 返回的元素的集合 </span><br><span class="line">	获取标签体内容</span><br><span class="line">		text(); ---&gt;获取一个元素下,所有的纯文本内容</span><br><span class="line">		html();---&gt;获取一个标签下所有的内容,包含子标签</span><br><span class="line">	获取属性所对应的值</span><br><span class="line">		String attr(&quot;属性名&quot;); ----&gt; 根据属性名获取属性值</span><br><span class="line">选择器</span><br><span class="line">	#id ---&gt;id选择器</span><br><span class="line">	元素名 ---&gt;元素选择器</span><br><span class="line">	元素名[属性名=&apos;属性值&apos;] ---&gt;属性选择器</span><br><span class="line">	元素名1 元素名2 ---&gt; 找&quot;元素名1&quot;下的所有&quot;元素名2&quot;</span><br><span class="line">	元素名1 &gt; 元素名2 ---&gt; 找&quot;元素名1&quot;下的一级&quot;元素名2&quot;</span><br><span class="line">XPath</span><br><span class="line">	主要: 要额外导入xpath的包</span><br><span class="line">	是一种xml的路径表现形式, 作用:就是为了定义xml中某个元素</span><br><span class="line">	语法:</span><br><span class="line">		// ---&gt;忽略层级</span><br><span class="line">			例如:</span><br><span class="line">				//student ---&gt;忽略层级查找student标签</span><br><span class="line">		/ ---&gt; 一级</span><br><span class="line">			例如:</span><br><span class="line">				//student/age --&gt; 找student下的一级age标签</span><br><span class="line">		@属性名 ---&gt; 按照属性名查找元素</span><br><span class="line">			例如:</span><br><span class="line">				//student[@name] ---&gt; 查找student元素,但是要求student上有name属性</span><br><span class="line">		@属性名=&apos;属性值&apos; ----&gt;按照属性名和属性值查找元素</span><br><span class="line">			例如:</span><br><span class="line">				//student[@name=&apos;aaa&apos;] ---&gt; 查找student元素,但是要求student上有name属性,而且值为aaa</span><br></pre></td></tr></table></figure>
<h2 id="注解"><a href="#注解" class="headerlink" title="注解"></a>注解</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">一. 概念：说明程序的。给计算机看的,或者框架编写看的</span><br><span class="line">	注释：用文字描述程序的。给程序员看的</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line">	定义：注解（Annotation），也叫元数据。一种代码级别的说明。它是JDK1.5及以后版本引入的一个特性，与类、接口、枚举是在同一个层次。</span><br><span class="line">		它可以声明在包、类、字段、方法、局部变量、方法参数等的前面，用来对这些元素进行说明，注释。</span><br><span class="line">	概念描述：</span><br><span class="line">		JDK1.5之后的新特性</span><br><span class="line">		说明程序的</span><br><span class="line">		使用注解：@注解名称(给属性赋值)</span><br><span class="line">		</span><br><span class="line">	</span><br><span class="line">	重要作用：</span><br><span class="line">		1.携带数据取代部分xml(框架用的东西!!!!!!!!)</span><br><span class="line">		2.编译检查.例如,@Override @FunctionalInterface等等</span><br><span class="line"></span><br><span class="line">	JDK中预定义的一些注解</span><br><span class="line">		@Override	：检测被该注解标注的方法是否是继承自父类(接口)的</span><br><span class="line">		@Deprecated ：该注解标注的内容，表示已过时</span><br><span class="line">		@SuppressWarnings：压制警告</span><br><span class="line">			一般传递参数all  @SuppressWarnings(&quot;all&quot;)</span><br></pre></td></tr></table></figure>
<h3 id="自定义注解"><a href="#自定义注解" class="headerlink" title="自定义注解"></a>自定义注解</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line">定义一个类:</span><br><span class="line">	public class 类名&#123;</span><br><span class="line">		成员变量</span><br><span class="line">		成员方法</span><br><span class="line">		构造函数</span><br><span class="line">	</span><br><span class="line">	&#125;</span><br><span class="line">	public interface 接口名&#123;</span><br><span class="line">		常量</span><br><span class="line">		抽象方法</span><br><span class="line">	&#125;</span><br><span class="line">	public @interface aaa&#123;//原来你的本质是接口</span><br><span class="line">		</span><br><span class="line">		抽象方法</span><br><span class="line">		public abstract int age();</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	@aaa(age=18)// 相当于定义一个类,实现了aaa接口,并重写了age方法,讲这个方法返回值改成18</span><br><span class="line">	</span><br><span class="line">格式：</span><br><span class="line">	元注解</span><br><span class="line">	public @interface 注解名称&#123;</span><br><span class="line">		属性列表;(抽象方法)</span><br><span class="line">		public abstract 数据类型 方法名();</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">本质：注解本质上就是一个接口，该接口默认继承Annotation接口</span><br><span class="line">	public interface Anno extends java.lang.annotation.Annotation &#123;&#125;</span><br><span class="line">	内容: 只能定义常量,抽象方法;</span><br><span class="line">注解的实现类如何定义?</span><br><span class="line">	在使用注解的时候, 只需要对抽象方法返回值进行赋值, 就可以了;</span><br><span class="line"></span><br><span class="line">属性：注解中的抽象方法</span><br><span class="line">	要求：</span><br><span class="line">		1.抽象方法的返回值类型有下列取值</span><br><span class="line">			基本数据类型</span><br><span class="line">			String</span><br><span class="line">			枚举</span><br><span class="line">			注解</span><br><span class="line">			以上类型的一维数组</span><br><span class="line"></span><br><span class="line">		2. 定义了属性，在使用时需要给属性赋值</span><br><span class="line">			1. 如果定义属性时，使用default关键字给属性默认初始化值，则使用注解时，可以不进行属性的赋值。</span><br><span class="line">			2. 如果只有一个属性需要赋值，并且属性的名称是value，则value可以省略，直接定义值即可。</span><br><span class="line">			3. 数组赋值时，值使用&#123;&#125;包裹。如果数组中只有一个值，则&#123;&#125;可以省略</span><br><span class="line"></span><br><span class="line">元注解：用于描述注解的注解</span><br><span class="line">	@Target：描述注解能够作用的位置 ----&gt; 默认:如果你不写, 你的注解默认可以加在任何地方!!!!</span><br><span class="line">		ElementType取值：</span><br><span class="line">			TYPE：可以作用于类上</span><br><span class="line">			METHOD：可以作用于方法上</span><br><span class="line">			FIELD：可以作用于成员变量上</span><br><span class="line">	@Retention：描述注解被保留的阶段 ----&gt;如果你不写, 你的注解只有在&quot;源码&quot;中有效</span><br><span class="line">		* @Retention(RetentionPolicy.RUNTIME)：当前被描述的注解，会保留到class字节码文件中，并被JVM读取到</span><br><span class="line">		RESOURCE: 只在源码文件生效</span><br><span class="line">		CLASS: 在源码中,字节码文件中生效</span><br><span class="line">		RUNTIME: 在源码中,字节码文件中生效,内存中都生效</span><br><span class="line">			</span><br><span class="line">	@Documented：描述注解是否被抽取到api文档中</span><br><span class="line">	@Inherited：描述注解是否被子类继承</span><br></pre></td></tr></table></figure>
<h3 id="解析注解"><a href="#解析注解" class="headerlink" title="解析注解"></a>解析注解</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">在程序使用(解析)注解：获取注解中定义的属性值, 必须通过&quot;反射&quot;才可以获取注解</span><br><span class="line">1. 获取注解定义的位置的对象  （Class，Method,Field）</span><br><span class="line">2. 获取指定的注解,通过反射的三大对象(Field(字段),Method(方法),Class(类上)), 调用以下两个api可以获取和判断</span><br><span class="line">	Annotation getAnnotation(注解的字节码Class) ----&gt;获取身上的注解</span><br><span class="line">		其实就是在内存中生成了一个该注解接口的子类实现对象</span><br><span class="line">				public class ProImpl implements Pro&#123;</span><br><span class="line">					public String className()&#123;</span><br><span class="line">						return &quot;cn.itcast.annotation.Demo1&quot;;</span><br><span class="line">					&#125;</span><br><span class="line">					public String methodName()&#123;</span><br><span class="line">						return &quot;show&quot;;</span><br><span class="line">					&#125;</span><br><span class="line">				&#125;</span><br><span class="line">	boolean isAnnotationPresent(注解.class); ----&gt;判断注解是否存在</span><br><span class="line">3. 调用注解中的抽象方法获取配置的属性值</span><br></pre></td></tr></table></figure>

      
    </div>

    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java/" rel="tag"> <i class="fa fa-tag"></i> Java</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/10/28/Day38_BootStrap/" rel="next" title="Day38_BootStrap">
                <i class="fa fa-chevron-left"></i> Day38_BootStrap
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/10/30/Day40_tomcat&servlet/" rel="prev" title="Day40_tomcat&servlet">
                Day40_tomcat&servlet <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



<div class="post-spread">
      
        <!-- JiaThis Button BEGIN -->
<div class="jiathis_style">
<span class="jiathis_txt">分享到：</span>
<a class="jiathis_button_fav">收藏夹</a>
<a class="jiathis_button_copy">复制网址</a>
<a class="jiathis_button_email">邮件</a>
<a class="jiathis_button_weixin">微信</a>
<a class="jiathis_button_qzone">QQ空间</a>
<a class="jiathis_button_tqq">腾讯微博</a>
<a class="jiathis_button_douban">豆瓣</a>
<a class="jiathis_button_share">一键分享</a>

<a href="http://www.jiathis.com/share?uid=2140465" class="jiathis jiathis_txt jiathis_separator jtico jtico_jiathis" target="_blank">更多</a>
<a class="jiathis_counter_style"></a>
</div>
<script type="text/javascript">
var jiathis_config={
  data_track_clickback:true,
  summary:"",
  shortUrl:false,
  hideMore:false
}
</script>
<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=" charset="utf-8"></script>
<!-- JiaThis Button END -->
      
</div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/icon.jpg" alt="大狗">
            
              <p class="site-author-name" itemprop="name">大狗</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">45</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zhaowenhao99" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://zhaowenhao99.github.io" title="大狗之家" target="_blank">大狗之家</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Day39"><span class="nav-number">1.</span> <span class="nav-text">Day39</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#XML"><span class="nav-number">1.0.1.</span> <span class="nav-text">XML</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#xml的语法"><span class="nav-number">1.0.2.</span> <span class="nav-text">xml的语法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#xml的组成"><span class="nav-number">1.0.3.</span> <span class="nav-text">xml的组成</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#约束"><span class="nav-number">1.0.4.</span> <span class="nav-text">约束</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解析思想"><span class="nav-number">1.0.5.</span> <span class="nav-text">解析思想</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解析器"><span class="nav-number">1.0.6.</span> <span class="nav-text">解析器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常见的对象"><span class="nav-number">1.0.7.</span> <span class="nav-text">常见的对象</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#注解"><span class="nav-number">1.1.</span> <span class="nav-text">注解</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#自定义注解"><span class="nav-number">1.1.1.</span> <span class="nav-text">自定义注解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解析注解"><span class="nav-number">1.1.2.</span> <span class="nav-text">解析注解</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">大狗</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">39.5k</span>
  
</div>


  <div class="powered-by">个人专属</div>



  <span class="post-meta-divider">|</span>



<div class="powered-by">
<span id="sitetime"></span>
<script language="javascript">
  function siteTime(){
    window.setTimeout("siteTime()", 1000);
    var seconds = 1000;
    var minutes = seconds * 60;
    var hours = minutes * 60;
    var days = hours * 24;
    var years = days * 365;
    var today = new Date();
    var todayYear = today.getFullYear();
    var todayMonth = today.getMonth()+1;
    var todayDate = today.getDate();
    var todayHour = today.getHours();
    var todayMinute = today.getMinutes();
    var todaySecond = today.getSeconds();
    /* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
    year - 作为date对象的年份，为4位年份值
    month - 0-11之间的整数，做为date对象的月份
    day - 1-31之间的整数，做为date对象的天数
    hours - 0(午夜24点)-23之间的整数，做为date对象的小时数
    minutes - 0-59之间的整数，做为date对象的分钟数
    seconds - 0-59之间的整数，做为date对象的秒数
    microseconds - 0-999之间的整数，做为date对象的毫秒数 */
    var t1 = Date.UTC(2019,04,5,15,00,00); //北京时间2018-2-13 00:00:00
    var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
    var diff = t2-t1;
    var diffYears = Math.floor(diff/years);
    var diffDays = Math.floor((diff/days)-diffYears*365);
    var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
    var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
    var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
    document.getElementById("sitetime").innerHTML=" 已运行"+/*diffYears+" 年 "+*/diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
  }/*因为建站时间还没有一年，就将之注释掉了。需要的可以取消*/
  siteTime();
</script>
</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false});</script></body>
<script type="text/javascript" src="/js/src/clicklove.js"></script>
</html>
